package payment;

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import common.Payment;

public class CashManageServlet extends HttpServlet 
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException 
	{
		perform(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException 
	{
		perform(req, resp);
	}
	private void perform(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException 
	{
		//配達完了データの取得
		String s_number = req.getParameter("s_number");		//納品番号
		String date = req.getParameter("s_date");					//配達完了日
		//受け取ったデータがStringなのでData型に変換する処理
		Calendar c = Calendar.getInstance();
		c.set(Integer.parseInt(date.substring(0, 4)), Integer.parseInt(date.substring(4, 6)), Integer.parseInt(date.substring(6, 8)));
		Date d = c.getTime();
		//paymentテーブルに登録し、登録したデータを取得
		List<Payment> list = Payment.insert_payment(s_number, d);
		
		req.setAttribute("list", list);
//		resp.sendRedirect("http://192.168.3.190:8080/itenVII/operator/cashManage.jsp");
//		RequestDispatcher dispatcher = req.getRequestDispatcher("../operator/cashManage.jsp");
//		dispatcher.forward(req, resp);
	}
}
